import dayjs from 'dayjs';
import mongoose, { Schema } from 'mongoose';

export interface ICategory {
	_id: string;
	name: string;
	description: string;
	createdAt: string;
	updatedAt: string;
}

const CategorySchema = new Schema<ICategory>(
	{
		name: { type: String, required: true, unique: true },
		description: { type: String, required: true },
		createdAt: {
			type: String,
			default: () => dayjs().format('YYYY年MM月DD日 HH:mm:ss'),
		},
		updatedAt: {
			type: String,
			default: () => dayjs().format('YYYY年MM月DD日 HH:mm:ss'),
		},
	},
	{
		collection: 'category',
	}
);

export const CategoryModel = mongoose.model<ICategory>('Category', CategorySchema);
